<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>法援宝</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer_user.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>

    <script type="text/javascript" src="../script/mobile-detect.js"></script>
    <script type="text/javascript" src="../script/mobile-detect.min.js"></script>


</head>
<body>
<div id="secHeader">
  <header class="header">
      <!-- <a href="javascript:void(0);"  class="back_btn"><img src="../image/head-fanhui.png" alt=""></a> -->
      <h2>登录</h2>
      <a href="javascript:void(0);" class="qiandao_btn" onclick="aaplay('register')"  style="position: absolute;  right: 3%; top: 0; color: #fff;">注册</a>
      <!--<a href="javascript:void(0);" class="qiandao_btn"><img src="../image/qiandao.png" alt=""></a>-->
  </header>
</div>
<section class="login_choose">
    <ul>
        <li><a href="javascript:;" onclick="aaplay('login')">账号密码登录</a></li>
        <li class="active"><a href="javascript:;">手机快捷登录</a></li>

    </ul>
</section>
<section class="login_section">
    <div class="fyb_logo"><img src="../image/fyb_logo.png" alt=""></div>
    <div class="login_box">
        <ul>
            <li class="username"><input type="text" placeholder="请输入手机号" id='phone' name='phone'></li>
            <li class="tel_code"><input type="text" placeholder="请输入验证码" id='yzm' name='yzm'><span id='regyzm'>获取验证码</span></li>

            <!--<li class="user_code"><input type="text" placeholder="请输入推荐人邀请码(选填)" id='idno' name='idno'></li>-->
        </ul>
        <p class="agree">成功登录即表示您同意<a href="##"  onclick="aaplay('yhxy')">《用户协议》</a></p>
        <button class="login_submit" type="submit" onclick="login()">立即登录</button>
        <!--<p>如果该手机号为第一次登录，我们会直接为该 <br>手机号创建会员</p>-->
    </div>
    <div class="login_kinds" style="">
        <h6><span>第三方登录</span></h6>
        <ul>
            <li class="qq"><a href="javascript:;" onclick="sanfang_qq()"><img src="../image/ologin1.png" alt=""></a></li>
            <li class="wx"><a href="javascript:;" onclick="initWXBind()"><img src="../image/ologin2.png" alt=""></a></li>
            <li class="wb"><a href="javascript:;" onclick="initWBBind()"><img src="../image/ologin3.png" alt=""></a></li>
        </ul>
    </div>
</section>
<aside class="download">
    <a href="##" class="user_download">普通用户点击下载【法援宝】</a>
</aside>


</body>

<script>
    var mt
    console.log(loginphone)
    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });


        $('#phone').val($api.getStorage ('phone'));

        var md = new MobileDetect(
            'Mozilla/5.0 (Linux; U; Android 4.0.3; en-in; SonyEricssonMT11i' +
            ' Build/4.1.A.0.562) AppleWebKit/534.30 (KHTML, like Gecko)' +
            ' Version/4.0 Mobile Safari/534.30');

       var os = md.os();//获取系统  
       if (os == "iOS") {//ios系统的处理  
           mt=2
       }else if(os == "AndroidOS") {//Android系统的处理  
           mt=1
       }

        apk()


        // ios 登录检测是否安装第三方app
         check_qq();
         check_wx();
         check_wb();

    }


    function apk(){
        if(mt==1){
            var p={id:31};
        }else {
           var p={id:32};
        }
        api.ajax({
            url: webSiteUrl+'/app/public/ad',
            method: 'post',
            data: {

                values: p
            }
        }, function(ret, err) {


            if(ret.code==200){

                var tj=ret.data;
                if(tj != null){
                    $('.user_download').attr('href',webSiteUrl+tj.file);
                    $('.user_download').attr('download',webSiteUrl+tj.file);

                }
            }

        });

    }
    $('#phone').val(loginphone);

    $('#regyzm').click(function () {
        if($(this).hasClass('regyzm')==false){
            var phone=$('input[name=phone]').val();
            if(phone==''){
                alert("请输入手机号！");return;
            }else if(!/^1[345678]\d{9}$/.test(phone)){
                alert("手机号格式错误！");return;
            }

            var p={phone:phone,type:2};
            api.ajax({
                url: webSiteUrl+'/app/public/yzm',
                method: 'post',
                data: {

                    values: p
                }
            }, function(ret, err) {
                if(ret.code==200){

                    $('#regyzm').addClass('regyzm');
                    var num=60;
                    timer=setInterval(function(){
                        $('#regyzm').html(num+'秒');
                        num--;
                        if(num==0){
                            clearInterval(timer);
                            timer=null;
                            $('#regyzm').html('重新获取');
                            $('#regyzm').removeClass('regyzm');
                        }
                    },1000)

                    alert(ret.msg);

                }else{

                    alert(JSON.stringify(ret.data));
                }
            });

        }
    })

    function login(){
        var phone=$("input[name=phone]").val();
        var yzm=$("input[name=yzm]").val();
        //var idno=$("input[name=idno]").val();

        if(phone==''){
            alert("请输入手机号！");return;
        }else if(!/^1[345678]\d{9}$/.test(phone)){
            alert("手机号格式错误！");return;
        }else if(yzm==''){
            alert("请输入验证码！");return;
        }

        var p={phone:phone,yzm:yzm,type:2};
        api.ajax({
            url: webSiteUrl+'/app/public/login',
            method: 'post',
            data: {

                values: p
            }
        }, function(ret, err) {


            if(ret.code==200){
                alert(ret.msg)
                //alert(JSON.stringify(ret.data));
                $api.clearStorage();
                $api.setStorage('user',ret.data);
                $api.setStorage('phone',phone);

                aaplay('workbench')

            }else if(ret.code==202){
                alert(ret.msg)
                aaplay('register')


            }else{alert(ret.msg)}
        });

    }
    //qq登录
      function sanfang_qq(){
           var qq = api.require('qq');
           var openId = '';
           qq.installed(function(ret, err) {
               if (!ret.status) {
                   api.alert({ msg: "当前设备未安装QQ客户端" });
               } else {
                   qq.login(function(ret, err) {
                       if (ret.status) {
                           openId = ret.openId;
                           qq.getUserInfo(function(ret, err) {
                               if (ret.status) {
                                   //alert(JSON.stringify(ret.info));
                                   QQbindAccount(openId,ret.info.nickname,ret.info.figureurl_qq_1);
                               } else {
                                   api.alert({ msg: err.msg });
                               }
                           });
                       }
                   });
               }
           });
       }



       //qq登录传值
       function QQbindAccount(openid,nickname,imgurl){

         var dd = {openid:openid, type:2};
         var d = {openid:openid,type:2,'username':nickname,icon:imgurl};
         api.ajax({
             url: webSiteUrl+'/app/public/checkOpenid',
             method: 'post',
             data: {
                 values: dd
             }
         },function(ret, err){
             if (ret.code==200) {

               api.ajax({
                   url: webSiteUrl+'/App/public/three',
                   method: 'post',
                   data: {
                       values: d
                   }
               }, function(ret, err) {
                   if (ret.code == 200) {

                       $api.clearStorage();
                       $api.setStorage("user",ret.data);
                       aaplay('workbench')

                   }else{
                       alert(ret.msg);
                       //alert('222')
                   }
               });


             } else {

               api.openWin({
                   name: 'loginbang',
                   url: './loginbang.html',
                   pageParam: {
                       data: d
                   }
               });


             }
         });
       }



        //微信登录22222222222222222222222222222
         function initWXBind() {
           // alert('该功能暂未实现');
           // return;
           var wx = api.require('wx');
           var code = '';
           wx.isInstalled(function(ret, err) {
               if (!ret.installed) {
                   alert("当前设备未安装微信客户端");
               } else {
                   wx.auth({
                       apiKey: 'wx00ebcf3ca5271e58'
                   }, function(ret, err) {
                       if (ret.status) {
                         //  alert(JSON.stringify('code:'+ret.code));

                           wx.getToken({
                               code: ret.code
                           }, function(ret, err) {
                           //    alert(JSON.stringify(ret));
                               if (ret.status) {
                                    api.showProgress({
                                       style: 'default',
                                       animationType: 'fade',
                                       title: '授权成功',
                                       text: '绑定处理中...',
                                       modal: true
                                   });
                                   wx.getUserInfo({
                                       accessToken: ret.accessToken,
                                       openId: ret.openId
                                   }, function(ret, err) {
                                     //  alert("获取用户信息");
                                     //  alert(JSON.stringify(ret));
                                       if (ret.status) {
                                           // 绑定成功
                                           WXbindAccount(ret.openid,ret.nickname,ret.headimgurl);
                                           api.hideProgress();
                                       }
                                   });
                               } else {
                                   alert(err.code+','+err.msg);
                               }
                           });
                       }else{

                       }
                   });
               }
           });
       }



         function WXbindAccount(openid,nickname,imgurl) {
           var dd = {openid:openid, type:2};
           var d = {openid:openid,type:2,'username':nickname,icon:imgurl};
           api.ajax({
               url: webSiteUrl+'/app/public/checkOpenid',
               method: 'post',
               data: {
                   values: dd
               }
           },function(ret, err){
               if (ret.code==200) {

                 api.ajax({
                     url: webSiteUrl+'/App/public/three',
                     method: 'post',
                     data: {
                         values: d
                     }
                 }, function(ret, err) {
                     if (ret.code == 200) {

                         $api.clearStorage();
                         $api.setStorage("user",ret.data);
                         aaplay('workbench')

                     }else{
                         alert(ret.msg);
                         //alert('222')
                     }
                 });


               } else {

                 api.openWin({
                     name: 'loginbang',
                     url: './loginbang.html',
                     reload:true,
                     pageParam: {
                         data: d
                     }
                 });


               }
           });
       }




       //微博登录
        function initWBBind() {
           var weibo = api.require('weibo');
           weibo.isInstalled(function(ret) {
               if (!ret.status) {
                   alert('未安装新浪微博客户端');
               } else {
                   weibo.auth(function(ret, err) {
                       if (ret.status) {
                           weibo.getUserInfo({
                               token: ret.token,
                               userId: ret.userId
                           }, function(ret, err) {
                               if (ret.status) {
                                   //alert(JSON.stringify(ret.userInfo))
                                   WBbindAccount(ret.userInfo.id,ret.userInfo.screen_name,ret.userInfo.profile_image_url);
                               }
                           });
                       }
                   });
               }
           });
       }

       //微博传值
       function WBbindAccount(openid,nickname,imgurl) {
         var dd = {openid:openid, type:2};
         var d = {openid:openid,type:2,'username':nickname,icon:imgurl};
         api.ajax({
             url: webSiteUrl+'/app/public/checkOpenid',
             method: 'post',
             data: {
                 values: dd
             }
         },function(ret, err){
             if (ret.code==200) {

               api.ajax({
                   url: webSiteUrl+'/App/public/three',
                   method: 'post',
                   data: {
                       values: d
                   }
               }, function(ret, err) {
                   if (ret.code == 200) {

                       $api.clearStorage();
                       $api.setStorage("user",ret.data);
                       aaplay('workbench')

                   }else{
                       alert(ret.msg);
                       //alert('222')
                   }
               });


             } else {

               api.openWin({
                   name: 'loginbang',
                   url: './loginbang.html',
                   reload:true,
                   pageParam: {
                       data: d
                   }
               });


             }
         });

       }

</script>
</html>
